#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[250][250];
signed main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n ; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i][j] == a[i - 1][j] || a[i][j] == a[i][j - 1]) {
				a[i][j]++;
			}
		}
	}
	int MAX = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			MAX = max(MAX,a[i][j]);
		}
	}
	cout << MAX;
	return 0;
}
